#pragma once
#include "Common.h"
#include<unordered_map>
class Handler
{
private:
    std::unordered_map<std::string,std::string> umap;
public:
    std::string operator()(std::string key)
    {
        umap.insert(std::make_pair("linshen","林深"));
        umap.insert(std::make_pair("blog","博客"));

        std::unordered_map<std::string,std::string>::iterator iter = umap.find(key);
        if(iter != umap.end())
            key = iter->second;  
        return key;
    }
};
class Task
{
public:
    int accept_sock;
    std::string client_ip;
    uint16_t client_port;
    Handler handler;
public:
    Task() = default;
    Task(int sock,std::string ip,uint16_t port):accept_sock(sock),client_ip(ip),client_port(port){}
    void Execute()
    {
        std::cout << "Sock:" << accept_sock << "|IP Port->" << client_ip <<":" << client_port << std::endl;
        char buffer[1024];
        while(true)
        {
            size_t size = read(accept_sock,buffer,sizeof(buffer)-1);
            std::cout << "size :" << size << std::endl;
            buffer[size-2] = '\0';
            std::string key(buffer);
            key = handler(key);
            key += '\n';
            write(accept_sock,key.c_str(),key.size());
        }
    }
};